﻿using System;
using System.Configuration;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


public partial class MasterPages_Default : System.Web.UI.Page
{
    public int teller = 140;


    protected void Button15_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            // Get the name of the file to upload.
            string fileName = Server.HtmlEncode(FileUpload1.FileName);
            // Get the extension of the uploaded file.
            string extension = System.IO.Path.GetExtension(fileName);
            
            if ((extension == ".jpg") || (extension == ".jpeg") || (extension == ".png") || (extension == ".bmp") || (extension == ".png") || (extension == ".gif"))
            {
                Button15.BackColor = System.Drawing.Color.DarkRed;

                byte[] imageSize = new byte[FileUpload1.PostedFile.ContentLength];

                HttpPostedFile uploadImage = FileUpload1.PostedFile;

                uploadImage.InputStream.Read(imageSize, 0, FileUpload1.PostedFile.ContentLength);

                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

                SqlCommand cmd = new SqlCommand();

                cmd.CommandText = "INSERT INTO [Foto's_per_Abonnee] (Abonnee_ID, Foto, Profiel_Foto)VALUES (@Abonnee_ID, @Foto, 1)";
                
                cmd.CommandType = CommandType.Text;

                cmd.Connection = con;

                SqlParameter UploadedImage = new SqlParameter("@Foto", SqlDbType.Image, imageSize.Length);
                UploadedImage.Value = imageSize;

                
                SqlParameter userid = new SqlParameter("@Abonnee_ID", SqlDbType.Int);
                //userid.Value = Convert.ToInt32(Session["abonnee_ID"]);
                userid.Value = Convert.ToInt32(150);

                cmd.Parameters.Add(userid);
                cmd.Parameters.Add(UploadedImage);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();

                Button15.Text = "DONE";
                Button15.Enabled = false;
                FileUpload1.Visible = false;

            }




            }
            else
            {
                // Show message
            }
        }
    protected void btnVolgende3_Click(object sender, EventArgs e)
    {

        //SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

        //SqlCommand cmd = new SqlCommand();

        ////cmd.CommandText = "INSERT INTO [Profielen] (Abonnee_ID, Naam, Geslacht, GeboorteDatum, Land_ID, Postcode_ID, Grootte, Gewicht)" +
        ////    "VALUES (@Abonnee_ID, @Naam, @Geslacht, @GeboorteDatum, @Land_ID, @Postcode_ID, @Grootte, @Gewicht)";
        //cmd.CommandText = "INSERT INTO [Profielen] (Naam, Geslacht, Land_ID, Postcode_ID, Burgerlijke_Staat_ID, Studieniveau_ID, Sterrenbeeld_ID, Grootte, Gewicht, Kleur_Ogen, Roken_ID, Drankgebruik_ID, Moedertaal)" +
        //                                "VALUES (@Naam, @Geslacht, @Land_ID, @Postcode_ID, @Burgerlijke_Staat_ID, @Studieniveau_ID, @Sterrenbeeld_ID, @Grootte, @Gewicht, @Kleur_Ogen, @Roken_ID, @Drankgebruik_ID, @Moedertaal)";

        //cmd.CommandType = CommandType.Text;

        //cmd.Connection = con;
        //teller += 1;


        //SqlParameter p1 = new SqlParameter("@Naam", SqlDbType.NChar, 50);
        //p1.Value = TextBox1.Text + " " + TextBox2.Text;
        //SqlParameter p2 = new SqlParameter("@Geslacht", SqlDbType.NChar, 10);
        //p2.Value = RadioButtonList1.SelectedItem.Text;
        //SqlParameter p3 = new SqlParameter("@Land_ID", SqlDbType.Int);
        //p3.Value = Convert.ToInt32(DropDownList1.SelectedIndex);
        //SqlParameter p4 = new SqlParameter("@Postcode_ID", SqlDbType.Int);
        //p4.Value = Convert.ToInt32(TextBox10.Text);
        //SqlParameter p5 = new SqlParameter("@Burgerlijke_Staat_ID", SqlDbType.Int);
        //p5.Value = Convert.ToInt32(1);
        //SqlParameter p6 = new SqlParameter("@Studieniveau_ID", SqlDbType.Int);
        //p6.Value = 1;
        //SqlParameter p7 = new SqlParameter("@Sterrenbeeld_ID", SqlDbType.NChar, 50);
        //p7.Value = "Waterman";
        //SqlParameter p8 = new SqlParameter("@Grootte", SqlDbType.NChar, 3);
        //p8.Value = "180";
        //SqlParameter p9 = new SqlParameter("@Gewicht", SqlDbType.NChar, 3);
        //p9.Value = "80";
        //SqlParameter p10 = new SqlParameter("@Kleur_Ogen", SqlDbType.NChar, 30);
        //p10.Value = "Blauw";
        //SqlParameter p11 = new SqlParameter("@Roken_ID", SqlDbType.Int);
        //p11.Value = 1;
        //SqlParameter p12 = new SqlParameter("@Drankgebruik_ID", SqlDbType.Int);
        //p12.Value = 1;
        //SqlParameter p13 = new SqlParameter("@Moedertaal", SqlDbType.NChar, 50);
        //p13.Value = "Nederlands";




        //cmd.Parameters.Add(p1);
        //cmd.Parameters.Add(p2);
        //cmd.Parameters.Add(p3);
        //cmd.Parameters.Add(p4);
        //cmd.Parameters.Add(p5);
        //cmd.Parameters.Add(p6);
        //cmd.Parameters.Add(p7);
        //cmd.Parameters.Add(p8);
        //cmd.Parameters.Add(p9);
        //cmd.Parameters.Add(p10);
        //cmd.Parameters.Add(p11);
        //cmd.Parameters.Add(p12);
        //cmd.Parameters.Add(p13);

        //con.Open();
        //cmd.ExecuteNonQuery();
        //con.Close();



    }
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
        
        con.Open();
        SqlCommand com = new SqlCommand("select Land from [Landen]", con); // table name 
        SqlDataAdapter da = new SqlDataAdapter(com);
        DataSet ds = new DataSet();
        da.Fill(ds);  // fill dataset
        DropDownList1.DataTextField = ds.Tables[0].Columns["Land"].ToString(); // text field name of table dispalyed in dropdown
        DropDownList1.DataSource = ds.Tables[0];      //assigning datasource to the dropdownlist
        DropDownList1.DataBind();  //binding dropdownlist


        com = new SqlCommand("select Etniciteit from [Etniciteit]", con); // table name 
        da = new SqlDataAdapter(com);
        ds = new DataSet();
        da.Fill(ds);  // fill dataset
        DropDownList7.DataTextField = ds.Tables[0].Columns["Etniciteit"].ToString(); // text field name of table dispalyed in dropdown
        DropDownList7.DataSource = ds.Tables[0];      //assigning datasource to the dropdownlist
        DropDownList7.DataBind();  //binding dropdownlist




        con.Close();

    }
}


